﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMasterPage.master" AutoEventWireup="true" CodeFile="teachermanage.aspx.cs" Inherits="Admin_teachermanage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link type='text/css' href='../css/basic.css' rel='stylesheet' media='screen' />
<!-- IE6 "fix" for the close png image -->
<!--[if lt IE 7]>
<link type='text/css' href='../css/basic_ie.css' rel='stylesheet' media='screen' />
<![endif]-->

<script type="text/javascript" src="../js/jquery/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="../js/jquery/jquery.hoverIntent.min.js"></script>
<script type='text/javascript' src='../js/jquery/jquery.simplemodal.js'></script>
<script type="text/javascript" src="../js/jquery/jquery.ajaxfileupload.js"></script>
<script>
    $(function () {
        $("#dg tbody tr").hoverIntent(
        function () { $(this).children().css("background-color", "#F2F4F6"); },
        function () { $(this).children().css("background-color", "#FFFFFF"); }
    );
        $('#BtnAdd').click(function (e) {
            $('#Add-modal-content').modal({
                opacity: 55, zIndex: 10,
                onOpen: function (dialog) {
                    dialog.overlay.fadeIn('fast', function () {
                        dialog.data.hide();
                        dialog.container.fadeIn('fast', function () {
                            dialog.data.show(); //slideDown('slow');
                        });
                    });
                }
            });
            return false;
        });
        $("#BtnImport").click(function (e) {
            $('#Import-modal-content').modal({
                opacity: 55, zIndex: 10,
                onOpen: function (dialog) {
                    dialog.overlay.fadeIn('fast', function () {
                        dialog.data.hide();
                        dialog.container.fadeIn('fast', function () {
                            dialog.data.show(); //slideDown('slow');
                        });
                    });
                }
            });
            return false;
        });
        $("#BtnDel").click(function (e) {
            confirm("你确定要删除选中的考生么?<br>该操作不可删除。", function () {
                //window.location.href = window.location.href;
                var chk = "";
                $("input[name=chkStudent]").each(function () {
                    //$(this).attr("checked", !this.checked);
                    if ($(this).attr("checked")) {
                        chk += $(this).val() + ",";
                    }
                });
                if (chk != "") {
                    var array = chk.split(',');
                    for (var i = 0; i < array.length; i++) {
                        if (array[i] != "") { delStu(chk); }
                    }
                    alert("删除完成");
                    window.location.href = window.location.href;
                } else {
                    alert("您没有选中任何考生"); $.modal.close();
                }
            });
        });

    });

</script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td align=left><b>培训师列表</b></td></tr>
</table>


<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td align=left> 
    <a href='#' id='BtnAdd' class="abtn_add">增加培训师</a>
    </td></tr>
<tr>
<td>
    <table id="dg" class="grid" cellspacing="0" cellpadding="0" width="100%">
        <thead>
            <tr>
                <th width=5%>选择</th>
                <th >培训师名称</th>
                <th >所属部门</th>
                <th width=15%>操作</th>
            </tr>
        </thead>
        <tbody>
        <asp:Repeater ID="rp" runat="server" EnableViewState=false>
        <ItemTemplate>
            <tr>
                <td><input id="chk<%# Eval("MasterID")%>" name="chkStudent" value='<%# Eval("MasterID")%>' type="checkbox" /></td>
                <td><%# Eval("MasterName")%></td>
                <td><%# getDepart(Eval("DepartmentID").ToString().Trim())%></td>
                <td>
                <a href="#" onclick="EditStu('<%# Eval("MasterID")%>','<%# Eval("MasterName")%>','<%# Eval("DepartmentID")%>')">编辑</a> &nbsp;
                <a href="#" onclick='delSingleStu(<%# Eval("MasterID")%>)'>删除</a></td>
            </tr>
        </ItemTemplate>
        </asp:Repeater>
        </tbody>
    </table>
</td>

</tr>
</table>


<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
    <table class="grid" border="0" cellspacing="0" cellpadding="0" width="100%">
        <thead>
            <tr>
                <th>统计：共有 <asp:Label ID="LibStuCount" runat="server" Text="0"></asp:Label>培训师 </th>
            </tr>
        </thead>
    </table>
</td>
</tr>
</table>

<div id="Add-modal-content">
    <div class="modal-div">培训师名称：<input id="stuNum" type="text" />(必填)登录用</div>
    <div class="modal-div">登录密码：<input id="stuPas" type="text" />(必填)(登录用)</div>
    <div class="modal-div">重复密码：<input id="rePas" type="text" />(必填)</div>
    <div class="modal-div">所属部门：<%--<asp:DropDownList ID="departddl" runat="server"></asp:DropDownList>--%>
    <asp:CheckBoxList ID="departddl" RepeatDirection="Horizontal" runat="server">
    </asp:CheckBoxList>
                            </div>
    <div class="modal-div">
    <span style="float:left;margin-left:20px;">
    <input id="Button3" type="button" class="btn" onclick="addNew()" value="增加" />
    <input id="btnCancle" type="button" class="btn" value="取消" onclick="Cancle()" />
    </span>
    <span id="statusAdd" class="status" style="display:none;font-size:0.8em;padding-top:5px;">
    <img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" />添加中请稍候...
    </span>
    </div>
</div>


<div id='confirm'>
	<div class='header'><span>注意</span></div>
	<div class='message'></div>
	<span id="statusDel" class="status" style="display:none;font-size:0.8em;padding-top:5px;">
    <img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" />添加中请稍候...
    </span>
	<div class='buttons'>
		<div class='no simplemodal-close'>取消</div>
		<div class='yes'>确定删除</div>
		
	</div>
</div>

<div id="Edit-modal-content">
    <div class="modal-div">培训师名称：<input id="EditstuNum" type="text" />(必填)登录用 </div>
    <div class="modal-div">登录密码：<input id="stuPas2" type="text" />(必填)(登录用)</div>
    <div class="modal-div">重复密码：<input id="rePas2" type="text" />(必填)</div>
    <div class="modal-div">所属部门：
    <%--<asp:DropDownList ID="departddl2" runat="server"></asp:DropDownList>--%>
    <asp:CheckBoxList ID="departddl2" RepeatDirection="Horizontal" runat="server">
    </asp:CheckBoxList>
                            <input id="EditstuId" type="hidden" value="" />
                            </div>
    <div class="modal-div">
    <span style="float:left;margin-left:20px;">
    <input id="Button4" type="button" class="btn" onclick="btnEdit()" value="修改" />
    <input id="Button5" type="button" class="btn" value="取消" onclick="Cancle()" />
    </span>
    <span id="statusEdit" class="status" style="display:none;font-size:0.8em;padding-top:5px;">
    <img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" />修改中请稍候...
    </span>
    </div>
</div>

<script>
    function addNew() {
        var name = $("#stuNum").val();
        var stuPas = $("#stuPas").val();
        var rePas = $("#rePas").val();
        //var deptid = $("#<%=departddl.ClientID %>").val();
        var deptid = ""; //保存checkbox选中值
        //遍历name以listTest开头的checkbox
        $("input[name^='ctl00$ContentPlaceHolder1$departddl$']").each(function () {
            if (this.checked) {
                //$(this):当前checkbox对象;
                deptid += $(this).val() + ",";
            }
        });
        
        if (name == "") { alert("请输入培训师名字"); return false; }
        if (stuPas == "") { alert("请输入密码"); return false; }
        if (stuPas != rePas) { alert("两次输入的密码不一致"); return false; }
        if (deptid == "") { alert("请选择该培训师可管理部门"); return false; }
        $.ajax({
            type: "POST",
            cache: false,
            url: "Service/addmaster.aspx",
            data: "name=" + name + "&deptid=" + deptid + "&pwd=" + stuPas,
            beforeSend: function () {
                $(".status").show();
                $("#btnCancle").attr('disabled', true);
                $("#btnAdd").attr('disabled', true);
            },
            success: function (msg) {
                if (msg == "1") {
                    if (confirm("添加成功,是否继续添加？")) {
                        $("#stuNum").val("");
                    } else {
                        $(".status").hide();
                        $("#btnCancle").attr('disabled', false);
                        $("#btnAdd").attr('disabled', false);
                        $.modal.close();
                        window.location.href = location.href;
                    }
                } else {
                    alert("添加失败！请重新添加.");
                }

            },
            error: function (msg) {
                $(".status").hide();
                $("#btnCancle").attr('disabled', false);
                $("#btnAdd").attr('disabled', false);
                alert("发生错误,请重新添加.");
            }
        });
    }
    function Cancle() {
        $.modal.close();
    }
    function confirm(message, callback) {
        $('#confirm').modal({
            closeHTML: "<a href='#' title='关闭' class='modal-close'>x</a>",
            //position: ["20%", ],
            overlayId: 'confirm-overlay',
            containerId: 'confirm-container',
            onShow: function (dialog) {
                var modal = this;
                $('.message', dialog.data[0]).append(message);
                // if the user clicks "yes"
                $('.yes', dialog.data[0]).click(function () {
                    // call the callback
                    if ($.isFunction(callback)) {
                        callback.apply();
                    }
                    // close the dialog
                    //modal.close(); // or $.modal.close();
                });
            }
        });
    }
    function EditStu(id, stuNum,deptid) {
        $('#Edit-modal-content').modal({
            opacity: 55, zIndex: 10,
            onOpen: function (dialog) {
                dialog.overlay.fadeIn('fast', function () {
                    //赋值
                    $("#EditstuId").val(id);
                    $("#EditstuNum").val(stuNum);
                    //$("#<%=departddl2.ClientID %>").val(deptid);
                    dialog.data.hide();
                    dialog.container.fadeIn('fast', function () {
                        dialog.data.show(); //slideDown('slow');
                    });
                });
            }
        });
        return false;
    }
    function btnEdit() {
        var stuId = $("#EditstuId").val();
        var name = $("#EditstuNum").val();
        var stuPas = $("#stuPas2").val();
        var rePas = $("#rePas2").val();
        //var deptid = $("#<%=departddl2.ClientID %>").val();
        var deptid = ""; //保存checkbox选中值
        //遍历name以listTest开头的checkbox
        $("input[name^='ctl00$ContentPlaceHolder1$departddl2$']").each(function () {
            if (this.checked) {
                //$(this):当前checkbox对象;
                deptid += $(this).val() + ",";
            }
        });
        if (name == "") { alert("请输入培训师名字"); return false; }
        if (stuPas == "") { alert("请输入密码"); return false; }
        if (stuPas != rePas) { alert("两次输入的密码不一致"); return false; }
        if (deptid == "") { alert("请选择该培训师可管理部门"); return false; }
        $.ajax({
            type: "POST",
            cache: false,
            url: "Service/Editmaster.aspx",
            data: "id=" + stuId + "&name=" + name + "&pwd=" + stuPas + "&deptid=" + deptid,
            beforeSend: function () {
                $(".status").show();
                $("#Button4").attr('disabled', true);
                $("#Button5").attr('disabled', true);
            },
            success: function (msg) {
                if (msg == "1") {
                    $.modal.close();
                    window.location.href = location.href;
                } else {
                    alert("修改失败！请重新修改.");
                }

            },
            error: function (msg) {
                $(".status").hide();
                $("#Button4").attr('disabled', false);
                $("#Button5").attr('disabled', false);
                alert("发生错误,请重新修改.");
            }
        });

    }

    function del(id) {
        $.ajax({
            type: "POST",
            cache: false,
            url: "Service/delmaster.aspx",
            data: "id=" + id,
            beforeSend: function () {
                $(".status").show();
            },
            success: function (msg) {
                if (msg == "1") { alert("删除成功！"); $.modal.close(); window.location.href = window.location.href; } else { alert("删除失败！请重新删除."); $.modal.close(); }
            },
            error: function (msg) {
                alert("发生错误,请重新删除."); $.modal.close();
            }
        });
    }
    function delSingle(id) {
        confirm("你确定要删除选中的培训师么?\r\n该操作不可恢复。", function () {
            del(id);
        });
    }

</script>

</asp:Content>
